;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Report.PayBackLedger", [])
        .controller("PayBackLedgerCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$filter", "$timeout", "UserContextService", "$stateParams", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $filter, $timeout, UserContextService, $stateParams) {
            $scope.markInfo = {
                curRow: -1
            };

            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };

            $scope.exportParam = {
                allUrl: ybHttp.RequestUrl("dReport", "/newreport/exprotRepaymentLedger")
            };

            $scope.toolbarConfig = {
                showAdvanceSearch: false,
                showColConfig: false,
            };
            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.condition = {};
            $scope.dataList = [];

            $scope.tbConf = {
                scrollWidth: 2000,
                tableCol: [
                    {
                        name: "回款单号",
                        dataField: "checkOrder",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "发货通知单编号",
                        dataField: "deliveryBillNo",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "客户SAP编码",
                        dataField: "dealerCode",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "客户名称",
                        dataField: "purchaseOrgName",
                        width: 160,
                        isShow: true
                    },
                    {
                        name: "付款人单位",
                        dataField: "repayOrgName",
                        width: 160,
                        isShow: true
                    },
                    {
                        name: "回款类型",
                        dataField: "reMoneyTypeShow",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "办事处",
                        dataField: "agency",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "回款日期",
                        dataField: "createDateShow",
                        width: 140,
                        isShow: true
                    },
                    {
                        name: "本次回款金额",
                        dataField: "checkPrice",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "付款方式",
                        dataField: "payDesc",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "制单业务员",
                        dataField: "operatorName",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "合同号",
                        dataField: "billContractNo",
                        width: 120,
                        isShow: true
                    },
                    {
                        name: "备注",
                        dataField: "remark",
                        width: 120,
                        isShow: true
                    },
                ]
            };

            $scope.reset = function () {
                $scope.condition = {};
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };

            $scope.selectRow = function (index) {
                $scope.markInfo.curRow = index;
            };

            $scope.checkDate = function (obj, startFiled, endFiled) {
                var timeFormatObj = ybWidget.CheckDate(obj[startFiled], obj[endFiled]);
                if (!!timeFormatObj.tStart) {
                    obj[startFiled] = timeFormatObj.tStart;
                }
                if (!!timeFormatObj.tEnd) {
                    obj[endFiled] = timeFormatObj.tEnd;
                }
            };

            function getDataList(curPage) {
                $scope.markInfo.curRow = -1;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }

                var service = "dReport";
                var reqUrl = "/newreport/repaymentLedgerInfo";
                var param = {
                    pageNum: $scope.pageInfo.curPage,
                    pageSize: $scope.pageInfo.pageSize,
                    filters: angular.copy($scope.condition)
                };
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.createDateShow = $filter("YbDate")(item.createDate, 'yyyy-MM-dd HH:mm:ss');
                        item.reMoneyTypeShow = $filter("ReMoneyTypeF")(item.reMoneyType);
                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                });
            }

            (function () {
                getDataList();
            })();
        }])
    ;
})(window, window.angular);